package va.radiomaria.gui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import va.radiomaria.audio.Mood;

/**
 * Represents an Icon that shows the current mood played by the radio
 * The image resource displayed depends on whether the Mood represented
 * by this icon is currently selected or not. 
 */
public class MoodIcon extends JPanel {
	private static final long serialVersionUID = 1L;
	private BufferedImage passiveIcon = null; //icon if mood is currently not selected
	private BufferedImage activeIcon = null; //icon if mood is currently selected
	private Mood mood = Mood.PARTY;
	private boolean isActive = false;

	
	public MoodIcon(String activeImagePath, String passiveImagePath, Mood mood, MouseListener listener) {
		this.setBackground(MainView.BACKGROUND_COLOR);
		try {
			this.activeIcon = ImageIO.read(new File(activeImagePath));
			this.passiveIcon = ImageIO.read(new File(passiveImagePath));
		} catch (IOException e) {
			e.printStackTrace();
		}
		this.mood = mood;
		addMouseListener(listener);
		this.setPreferredSize(new Dimension(40,40));
	}
	
	public Image getCurrentImage() {
		if(isActive) {
			return activeIcon;
		}
		else {
			return passiveIcon;
		}
	}
	
	public void setIsActive(boolean value) {
		this.isActive = value;
	}
	
	public Mood getMood() {
		return mood;
	}
	
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		g.drawImage(getCurrentImage(), 0, 0, null);
	}	
}
